/**
 * Created by dev-001 on 2017/3/18.
 * 题组
 */
import mongoose from 'mongoose';
const Schema = mongoose.Schema;
const ObjectId = Schema.Types.ObjectId;

const PositionSchema = new Schema({
    x: Number,
    y: Number
});
const QuestionNoSchema = new Schema({
    no: Number
});

const QuestionGroupSchema = new Schema({
    name: String,
    exam: {
        type: ObjectId,
        ref: 'Exam'
    },
    type: Number,//选取类型
    optionsNo: Number,//ABCD选项数量
    col: Number,
    row: Number,
    positions: [PositionSchema],
    ranges: [QuestionNoSchema],//题号范围
    range: [QuestionNoSchema],//todo临时修改
    direction: Number,
    attachment: {
        type: ObjectId,
        ref: 'Attachment'
    },
    createdAt: Date,
    updatedAt: Date
});

QuestionGroupSchema.pre('save', function (next) {
    this.createdAt = new Date();
    next();
});

export default mongoose.model('QuestionGroup', QuestionGroupSchema);